Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: udc_rpi_pico: replace message queue with k_events and minor fixes #87506

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jfischer-no
Copy link
Collaborator

Replace message queue with k_events, support VBUS state change detection, fix clear/set endpoint halt.

@jfischer-no jfischer-no added area: Drivers area: USB Universal Serial Bus Experimental Experimental features not enabled by default labels Mar 22, 2025
@jfischer-no jfischer-no requested a review from tmon-nordic March 22, 2025 12:06
tmon-nordic
tmon-nordic previously approved these changes Mar 24, 2025
Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not at USB expert, so I'm reviewing this as a general "if I had to fix it, would I be able to grok it?".

On that note, I think this is well-written, and the changes are clear. One small clarification question/comment from me.


k_msgq_get(&drv_msgq, &evt, K_FOREVER);
ep_cfg = udc_get_ep_cfg(dev, evt.ep);
evt = k_event_wait(&priv->events, UINT32_MAX, false, K_FOREVER);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be either:

  1. The bitmask of all the defined events (e.g. (RPI_PICO_EVT_XFER_FINISHED << 1) - 1) or similar. Or:
  2. Should there be some checking (maybe an assert) that at the bottom of this function all events bits have been handled?

Inspection of the code says "yes, everything defined in the enum is covered below", but it feels like it'd be possible to get out of sync here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpi_pico_thread_handler() is called within endless loop (static void udc_rpi_pico_thread_##n(void *dev, void *arg1, void *arg2) so there's no need for checking that all event bits have been handled.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more thinking along the lines of "if someone adds a new event, will they handle it?" but perhaps I'm suggesting an overly defensive programming style that can be countered with "if another person adds bad code... they shouldn't ", which is valid implementation strategy.

@jfischer-no
Copy link
Collaborator Author

jfischer-no commented Mar 31, 2025

Rebases on main to get changes from #87480

Comment on lines 65 to 66
struct k_event xfer_new;
struct k_event xfer_finished;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is not quite necessary to use k_event here. There is no need to wait for xfer_new nor xfer_finished and therefore atomic_t is enough. atomic_t is either 32-bit or 64-bit, but just 32-bit is sufficient here. See #87942 for a change in DWC2 driver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented in #87758, see also last commit here.

Set suspended state on suspend/resume ISR.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Using k_events eliminates the drawback of the queue potentially dropping
messages and provides a reliable event notification mechanism. It is
similar to commit c2f2d8c
("drivers: usb: udc_dwc2: Replace queue with events")

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Support VBUS state change detection and enable/disable DP pull-up
according to VBUS state when pinctrl property is provided.

It brings the similar functionality introduced in commit 4c0317f
("drivers: usb_dc_rpi_pico: Implemented vbus detection handling")
for the legacy device controller driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Mark endpoint as not busy after transfer is canceled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
For the IN endpoint, we only need to set/reset the STALL bit in the
endpoint control register.
To set halt on the OUT endpoint, the AVAILABLE bit must also be set,
which is similar to starting a new transfer, but first any transfer in
progress must be canceled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Do not check if the tailroom is greater than or equal to MPS because the
controller does not write directly to the buffer and therefore cannot
write outside the buffer.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
At high throughput, the controller sometimes fails to start a new
transaction. Clearing the corresponding endpoint bit in the BUFF_STATUS
completion register before initiating a new transaction solves this
problem.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use uint32_t instead of k_event for event value passing and
saves a few CPU cycles.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@jfischer-no jfischer-no force-pushed the pr-udc-rp_pico-rework branch from 3de4957 to d319420 Compare April 1, 2025 14:04
@jfischer-no
Copy link
Collaborator Author

Rebases on main to get changes from #87758

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Drivers area: USB Universal Serial Bus Experimental Experimental features not enabled by default platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants